/*  
 * Actipro Software's WPF DataGrid / Editors Integration Add-on
 * http://actipro.codeplex.com/
 * 
 * Copyright (c) 2009-2015 Actipro Software LLC. 
 *  
 * This source code is subject to the terms of the Microsoft Public License (Ms-PL). 
 *  
 * Redistribution and use in source and binary forms, with or without modification, 
 * is permitted provided that redistributions of the source code retain the above 
 * copyright notices and this file header. 
 *  
 * Additional copyright notices should be appended to the list above. 
 * 
 * For details, see <http://www.opensource.org/licenses/ms-pl.html>. 
 *  
 * All other rights reserved. 
 *
 */  


using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Controls;
using ActiproSoftware.Windows.Controls.Editors.Interop.DataGrid.Primitives;

namespace ActiproSoftware.Windows.Controls.Editors.Interop.DataGrid {

	/// <summary>
	/// Represents a data-bound column for use in a <c>DataGrid</c> that utilizes the <see cref="EnumEditBox"/>.
	/// </summary>
	public class DataGridEnumColumn : DataGridTypeSpecificEditBoxColumnBase<Enum> {

		#region Dependency Properties

		/// <summary>
		/// Identifies the <see cref="EnumListBoxStyle"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="EnumListBoxStyle"/> dependency property.</value>
		public static readonly DependencyProperty EnumListBoxStyleProperty = EnumEditBox.EnumListBoxStyleProperty.AddOwner(typeof(DataGridGuidColumn),
			new FrameworkPropertyMetadata(null, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="EnumType"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="EnumType"/> dependency property.</value>
		public static readonly DependencyProperty EnumTypeProperty = EnumEditBox.EnumTypeProperty.AddOwner(typeof(DataGridGuidColumn),
			new FrameworkPropertyMetadata(null, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="IsEditable"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="IsEditable"/> dependency property.</value>
		public static readonly DependencyProperty IsEditableProperty = EnumEditBox.IsEditableProperty.AddOwner(typeof(DataGridGuidColumn),
			new FrameworkPropertyMetadata(true, OnNotifyablePropertyValueChanged));

		/// <summary>
		/// Identifies the <see cref="UseDescriptionAttributes"/> dependency property.  This field is read-only.
		/// </summary>
		/// <value>The identifier for the <see cref="UseDescriptionAttributes"/> dependency property.</value>
		public static readonly DependencyProperty UseDescriptionAttributesProperty = EnumEditBox.UseDescriptionAttributesProperty.AddOwner(typeof(DataGridGuidColumn),
			new FrameworkPropertyMetadata(false, OnNotifyablePropertyValueChanged));

		#endregion // Dependency Properties
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		#region OBJECT
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Initializes the <see cref="DataGridEnumColumn"/> class.
		/// </summary>
		[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline")]
		static DataGridEnumColumn() {
			DropDownButtonVisibilityProperty.OverrideMetadata(typeof(DataGridEnumColumn), new FrameworkPropertyMetadata(Visibility.Visible, DropDownButtonVisibilityProperty.DefaultMetadata.PropertyChangedCallback));
		}

		#endregion // OBJECT

		/////////////////////////////////////////////////////////////////////////////////////////////////////
		#region PUBLIC PROCEDURES
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// <summary>
		/// Applies standard values to the specified target element.
		/// </summary>
		/// <param name="targetElement">The target element.</param>
		protected override void ApplyStandardValues(FrameworkElement targetElement) {
			if (targetElement is EnumEditBox) {
				this.ApplyValue(EnumListBoxStyleProperty, targetElement, EnumEditBox.EnumListBoxStyleProperty);
				this.ApplyValue(EnumTypeProperty, targetElement, EnumEditBox.EnumTypeProperty);
				this.ApplyValue(IsEditableProperty, targetElement, EnumEditBox.IsEditableProperty);
				this.ApplyValue(UseDescriptionAttributesProperty, targetElement, EnumEditBox.UseDescriptionAttributesProperty);
			}
			base.ApplyStandardValues(targetElement);
		}

		/// <summary>
		/// Gets or sets the <see cref="Style"/> applied to the <see cref="EnumListBox"/> used in default drop-down content.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// The <see cref="Style"/> applied to the <see cref="EnumListBox"/> used in default drop-down content.
		/// The default value is <see langword="null"/>.
		/// </value>
		public Style EnumListBoxStyle {
			get { return (Style)this.GetValue(DataGridEnumColumn.EnumListBoxStyleProperty); }
			set { this.SetValue(DataGridEnumColumn.EnumListBoxStyleProperty, value); }
		}

		/// <summary>
		/// Gets or sets the enumeration type associated with the value.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// The enumeration type associated with the value.
		/// The default value is <see langword="null"/>.
		/// </value>
		public Type EnumType {
			get { return (Type)this.GetValue(DataGridEnumColumn.EnumTypeProperty); }
			set { this.SetValue(DataGridEnumColumn.EnumTypeProperty, value); }
		}

		/// <summary>
		/// Gets the type of the edit box.
		/// </summary>
		/// <returns></returns>
		/// <returns>The <see cref="EnumEditBox"/> type.</returns>
		protected override Type GetEditBoxType() {
			return typeof(EnumEditBox);
		}

		/// <summary>
		/// Gets or sets a value indicating whether the underlying part is editable.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if the underlying part is editable; otherwise, <c>false</c>.
		/// The default value is <c>true</c>.
		/// </value>
		public bool IsEditable {
			get { return (bool)this.GetValue(DataGridEnumColumn.IsEditableProperty); }
			set { this.SetValue(DataGridEnumColumn.IsEditableProperty, value); }
		}

		/// <summary>
		/// Gets or sets a value indicating whether enumeration values should be displayed using an associated <c>DescriptionAttribute</c>, if any.
		/// This is a dependency property.
		/// </summary>
		/// <value>
		/// <c>true</c> if enumeration values should be displayed using an associated <c>DescriptionAttribute</c>, if any.; otherwise <c>false</c>.
		/// The default value is <c>false</c>.
		/// </value>
		public bool UseDescriptionAttributes {
			get { return (bool)this.GetValue(DataGridEnumColumn.UseDescriptionAttributesProperty); }
			set { this.SetValue(DataGridEnumColumn.UseDescriptionAttributesProperty, value); }
		}

		#endregion // PUBLIC PROCEDURES
	}
}
